package co.yixiang.modules.shop.repository;

import co.yixiang.modules.shop.domain.YxProductStockOut;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * @author frq
 * @date 2020-5-15
 */
public interface ProductStockOutRepository extends JpaRepository<YxProductStockOut, Integer>, JpaSpecificationExecutor<YxProductStockOut> {
    /**
     * 查询爬虫商品管理数据来源
     * @param name
     * @param value
     * @return
     */
    @Query(value = "select label from dict a inner join dict_detail b on a.id=b.dict_id where a.`name`=?1 and b.`value`=?2", nativeQuery = true)
    String findDataSourceName(String name, String value);

    /**
     * 查询商品分类ID,只取第一条
     * @param baseId
     * @return
     */
    @Query(value ="select yx.id from yx_store_category yx inner join yx_product_base yxp on yx.cate_name=yxp.category3 where yxp.id=?1 limit 1 ",nativeQuery = true)
    Integer findGoodsCateId(Integer baseId);
}
